const express = require('express')
const app = express()
const port = 7001
const file = require('./modules/file')
const qiniu = require('./modules/qiniu/index')
app.use('/file', file)
app.use('/qiniu', qiniu)

// 设置允许跨域
app.all('*', (req, res, next) => {
  // 设置允许跨域的域名
  res.header('Access-Control-Allow-Origin', '*')
  // 允许的header类型
  res.header('Access-Control-Allow-Headers', 'Content-Type')
  // 跨域允许的请求方式
  res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
  if (req.method.toLowerCase() === 'options') {
    // res.sendStatus(200)
  } else {
    next()
  }
})

// 测试接口
app.get('/', (req, res) => {
  res.send('Hello World')
})

app.listen(port, () => {
  console.log(`Server start in port ${port}`)
})